home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 October
/
CHIP Turkiye Ekim 2000.iso
/
prog
/
naps
/
04
/
setup.exe
/
Gnucleus
/
GnuSock.h
< prev
next >
Wrap
C/C++ Source or Header
|
2000-07-15
|
5KB
|
189 lines
#if !defined(AFX_GNUSOCK_H__60210B41_1340_11D4_ACF2_00A0CC533D52__INCLUDED_)
#define AFX_GNUSOCK_H__60210B41_1340_11D4_ACF2_00A0CC533D52__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// GnuSock.h : header file
//
#include <queue>
class QueryResult;
class CViewSearch ;
class QueryRequestItem
{
public:
QueryRequestItem (LPCTSTR szQuery, const GUID& guid) : m_query (szQuery), m_guid (guid) { }
QueryRequestItem (const QueryRequestItem& copy) : m_query (copy.m_query), m_guid (copy.m_guid) { }
virtual ~QueryRequestItem () { }
const CString& GetQuery () const { return m_query; }
const GUID& GetGuid () const { return m_guid; }
protected:
CString m_query;
GUID m_guid;
};
/////////////////////////////////////////////////////////////////////////////
// CGnuSock command target
// Seperate thread
class CGnuSock : public CAsyncSocket
{
// Attributes
public:
DWORD m_dwNumOfBadPackets; // counters
DWORD m_dwNumOfRecivedPackets;// Good packets
DWORD m_dwNumOfSentPackets;
// Operations
public:
CGnuSock();
CGnuSock(CGnuControl *pGnuComm);
virtual ~CGnuSock();
void Send_ConnectOK();
void Send_Ping();
void Send_Pong(GUID, int);
void Send_Query(CViewSearch *);
void Recieve_ConnectOK();
void Recieve_Ping(packet_Ping *, int);
void Recieve_Pong(packet_Pong *, int);
void Recieve_Push(packet_Push *, int);
void Recieve_Query(packet_Query *, int);
void Recieve_QueryReply(packet_QueryReply *, DWORD);
void Recieve_Unknown(byte *, int);
bool SpaceAvailable();
int SplitBundle(byte *, DWORD);
void HandlePacket(packet_Header *, int);
bool InspectPacket(packet_Header *, int);
void CleanUp();
// Remote hosts array, elements represent hop lengths
DWORD RemoteHosts[8];
void RefreshHostCount();
DWORD TotalRemoteHosts();
// Log string and options of what to append to it
CString Log;
bool logPings, logPongs, logQueries,
logPushes, logQueryReplies, logUnknowns,
logGUID, logHops, logTTL, logPayload, logDropped;
// Remote host and port of connnection
CString Host, Port;
bool Connected;
// Current search uses these variables
CString CurrentSearch;
GUID CurrentOrigin;
bool m_CanRelease;
// Link to next CGnuSock node in the list
CGnuSock *next;
CGnuControl *GnuComm;
// Overrides
public:
BOOL ProccessPacketQueue();
virtual int Send( const void* lpBuf, int nBufLen, int nFlags = 0 );
DWORD m_dwBytesIn; // for one period only
DWORD m_dwBytesOut; // for one period only
DWORD m_dwTotalBytesIn;
DWORD m_dwTotalBytesOut;
DWORD m_dwByteAllottmentOut;
DWORD m_dwByteAllottmentIn;
int m_iSizeOfPacketQueue;
void SendFileResults(std::queue <QueryResult> & resultQueue, GUID & Origin);
DWORD GetSecondsSinceLastContact(void)
{return ( CTime::GetCurrentTime() - m_timeLastHeardAT ).GetTotalSeconds();}
BOOL ShutDown(int nHow)
{
if(Connected)
{
Connected = false;
return (SOCKET_ERROR != shutdown(m_hSocket,nHow));
}
else
return FALSE;
}
void WantToDisconnect();
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGnuSock)
public:
virtual void OnConnect(int nErrorCode);
virtual void OnReceive(int nErrorCode);
virtual void OnClose(int nErrorCode);
//}}AFX_VIRTUAL
// Generated message map functions
//{{AFX_MSG(CGnuSock)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
// Implementation
protected:
CCriticalSection m_CritSecPacketQueue;
std::queue<void*> m_PacketsOutQueue;
std::queue<int> m_PacketsOutQueueSize;
void Initialize ();
CTime m_timeLastHeardAT; // hold time of last contact, for expiring non responding hosts.
int mExtraBytes;
byte *mExtraBytesStored;
};
class QueryResult
{
public:
QueryResult (DWORD dwIndex, DWORD dwSize, CString& szName) : m_index (dwIndex), m_size (dwSize), m_name (szName) { }
QueryResult (const QueryResult& copy) : m_index (copy.m_index), m_size (copy.m_size), m_name (copy.m_name) { }
virtual ~QueryResult () { }
inline DWORD GetSize () const { return m_name.GetLength () + 10; }
void CopyToBuffer (BYTE* buffer, DWORD dwSize) const
{
ASSERT (dwSize >= GetSize ());
* (XWORD*) buffer = flipX (makeX (m_index));
buffer += sizeof (XWORD);
* (XWORD*) buffer = flipX (makeX (m_size));
buffer += sizeof (XWORD);
::strcpy ((char*) buffer, m_name);
buffer += m_name.GetLength() + 1;
*buffer = '\0';
}
protected:
DWORD m_index;
DWORD m_size;
CString m_name;
// Not allowed
QueryResult ();
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_GNUSOCK_H__60210B41_1340_11D4_ACF2_00A0CC533D52__INCLUDED_)